package com.straw.jdk.algorithm.structure.stack;

/**
 * @author jianshan@byai.com
 * @date 2020/12/4 4:06 PM
 * describe:
 */
public class LinkedStack<T> {


    private StackNode<T> head;

    private int max;

    public boolean isEmpty() {
        return head == null;
    }


    public boolean push(T data) {
        if (data == null) {
            return false;
        }
        if (head == null) {
            head = new StackNode(data);
        } else {
            head = new StackNode(data, head);
        }
        return true;
    }

    public T pop() {
        T data = null;
        if (head == null) {
            return data;
        }
        StackNode<T> snapshot = head;
        data = snapshot.data;
        head = snapshot.next;
        return data;
    }


    private static class StackNode<T> {

        public StackNode(T data) {
            this.data = data;
            this.next = null;
        }

        public StackNode(T data, StackNode<T> next) {
            this.data = data;
            this.next = next;
        }

        /**
         * 泛型
         */
        private T data;
        private StackNode<T> next;

    }
}
